package com.thrd.basicframework.ui.recyclerview;

import android.graphics.Rect;
import android.util.Log;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

/**
 * @author: ${唐杰}
 * @date: 2021/3/22
 */
public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
    private int spaceLeft;
    private int spaceTop;
    private int spaceRight;
    private int spaceBottom;
    private int OneLeft;

    private int spanCounts;
    public SpacesItemDecoration(int spaceLeft,int spaceTop,int spaceRight,int spaceBottom) {
        this.spaceLeft = spaceLeft;
        this.spaceTop = spaceTop;
        this.spaceRight = spaceRight;
        this.spaceBottom = spaceBottom;
    }


    public void setOneLeft(int oneLeft,int spanCount) {
        this.OneLeft = oneLeft;
        this.spanCounts=spanCount;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view,
                               RecyclerView parent, RecyclerView.State state) {
        outRect.left = spaceLeft;
        outRect.right = spaceRight;
        outRect.bottom = spaceBottom;
        outRect.top = spaceTop;
//        LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager();
//        if(parent.getChildPosition(view) == 0){
//            if(layoutManager.getOrientation()==RecyclerView.HORIZONTAL){
//                outRect.left = 0;
//            }else{
//                outRect.top = 0;
//            }
//        }


        // Add top margin only for the first item to avoid double space between items
        int childPosition=parent.getChildPosition(view);
        int column=0;
        if(childPosition>0&&spanCounts>0){
            Log.e("getItemOffsets", "是否主线程childPosition="+childPosition+"spanCount"+spanCounts);
            column= childPosition % spanCounts; // 列数
        }else{
            column= 0; // 列数
        }

        if (column==0){
            outRect.left = OneLeft;
        }


    }





}
